package com.aia.prm.web.h7n9;

import java.util.Map;


import org.apache.log4j.Logger;
import org.apache.struts2.interceptor.SessionAware;
import org.springframework.util.StringUtils;

import com.aia.prm.domain.Qnfe;
import com.aia.prm.domain.VOLms;
import com.aia.prm.service.DefaultService;
import com.aia.prm.web.json.PrmForm2Json;
import com.cfh.ahead.Constant;
import com.cfh.util.Tools;
import com.opensymphony.xwork2.ActionSupport;
import com.opensymphony.xwork2.ModelDriven;

@SuppressWarnings({ "rawtypes", "serial" })
public class H7n9Form extends ActionSupport implements SessionAware, ModelDriven {
	private static final Logger logger = Logger.getLogger(PrmForm2Json.class);

	private Map session;
	private DefaultService defaultService;
	private Qnfe qnfe = new Qnfe();
	private String validate;

	public void validate() {
		try {
			{// 较验验证码
				String imgCode = (String) session.get(Constant.CAPTCHA_SESSION_HOLDER);
				if (!StringUtils.hasText(imgCode)) {
					addFieldError("imageCode", "请再次获取图片验证码");
					return;
				}

				if (!StringUtils.hasText(getValidate())) {
					addFieldError("imageCode", "请输入图片验证码");
					return;
				}
				if (!getValidate().toLowerCase().equals(imgCode)) {
					addFieldError("imageCode", "验证码输入错误");
					return;
				}
			}

		} catch (Exception e) {
			addFieldError("SERVER_ERROR", "未知错误");
			logger.error("" + e, e);
		}

	}

	public String execute() throws Exception {
		try {
			if (logger.isDebugEnabled()) {
				logger.debug("PrmForm1Json - start"); //$NON-NLS-1$
			}

			defaultService.H7n9Form(this);

			if (logger.isDebugEnabled()) {
				logger.debug("PrmForm1Json - end"); //$NON-NLS-1$
			}

			return Tools.smartReturn((ActionSupport) this);
		} catch (Exception e) {
			logger.error("Unknown Error:" + e, e);
			throw new RuntimeException(e);
		}
	}

	public void setSession(Map session) {
		this.session = session;
	}

	public Map getSession() {
		return session;
	}

	public Object getModel() {
		return getQnfe();
	}

	public DefaultService getDefaultService() {
		return defaultService;
	}

	public void setDefaultService(DefaultService defaultService) {
		this.defaultService = defaultService;
	}

	public Qnfe getQnfe() {
		return qnfe;
	}

	public void setQnfe(Qnfe qnfe) {
		this.qnfe = qnfe;
	}

	public String getValidate() {
		return validate;
	}

	public void setValidate(String validate) {
		this.validate = validate;
	}

}
